package com.g8.pethospitallearnbackend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.g8.pethospitallearnbackend.entity.User;
import com.g8.pethospitallearnbackend.entity.UserExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface UserMapper extends BaseMapper<User> {
    @SelectProvider(type=UserSqlProvider.class, method="countByExample")
    long countByExample(UserExample example);

    @DeleteProvider(type=UserSqlProvider.class, method="deleteByExample")
    int deleteByExample(UserExample example);

    @Delete({
        "delete from user",
        "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    int deleteByPrimaryKey(String userId);

    @Insert({
        "insert into user (user_id, user_role, ",
        "user_password, user_name, ",
        "user_gender, user_email, ",
        "user_birth, user_phone)",
        "values (#{userId,jdbcType=VARCHAR}, #{userRole,jdbcType=TINYINT}, ",
        "#{userPassword,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, ",
        "#{userGender,jdbcType=TINYINT}, #{userEmail,jdbcType=VARCHAR}, ",
        "#{userBirth,jdbcType=DATE}, #{userPhone,jdbcType=VARCHAR})"
    })
    int insert(User record);

    @InsertProvider(type=UserSqlProvider.class, method="insertSelective")
    int insertSelective(User record);

    @SelectProvider(type=UserSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="user_role", property="userRole", jdbcType=JdbcType.TINYINT),
        @Result(column="user_password", property="userPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_gender", property="userGender", jdbcType=JdbcType.TINYINT),
        @Result(column="user_email", property="userEmail", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_birth", property="userBirth", jdbcType=JdbcType.DATE),
        @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.VARCHAR)
    })
    List<User> selectByExample(UserExample example);

    @Select({
        "select",
        "user_id, user_role, user_password, user_name, user_gender, user_email, user_birth, ",
        "user_phone",
        "from user",
        "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    @Results({
        @Result(column="user_id", property="userId", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="user_role", property="userRole", jdbcType=JdbcType.TINYINT),
        @Result(column="user_password", property="userPassword", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_gender", property="userGender", jdbcType=JdbcType.TINYINT),
        @Result(column="user_email", property="userEmail", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_birth", property="userBirth", jdbcType=JdbcType.DATE),
        @Result(column="user_phone", property="userPhone", jdbcType=JdbcType.VARCHAR)
    })
    User selectByPrimaryKey(String userId);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    @UpdateProvider(type=UserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(User record);

    @Update({
        "update user",
        "set user_role = #{userRole,jdbcType=TINYINT},",
          "user_password = #{userPassword,jdbcType=VARCHAR},",
          "user_name = #{userName,jdbcType=VARCHAR},",
          "user_gender = #{userGender,jdbcType=TINYINT},",
          "user_email = #{userEmail,jdbcType=VARCHAR},",
          "user_birth = #{userBirth,jdbcType=DATE},",
          "user_phone = #{userPhone,jdbcType=VARCHAR}",
        "where user_id = #{userId,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(User record);
}